package dao;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;

import context.Context;

public class GetTable {
	private static final String DRIVER = "com.mysql.jdbc.Driver";


	public static ArrayList<String> getTable() throws Exception {

		String TABLE_NAME = "TABLE_NAME";
		String[] TABLE_TYPES = { "TABLE" };
		ArrayList<String> tablelist = new ArrayList<String>();

		Context c = Context.newInstance();
		Class.forName(DRIVER);
		Connection connection = DriverManager.getConnection(c.getConnection(), c.getUsrName(),
				c.getPsw());
		//Connection connection = Context.newInstance().getConnection();
		DatabaseMetaData dbmd = connection.getMetaData();

		ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES);
		int i = 0;
		while (tables.next()) {
			//System.out.println(tables.getString(TABLE_NAME));
			tablelist.add(tables.getString(TABLE_NAME));

		}

		connection.close();
		return tablelist;
	}
}